/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dtn.getdata;

import java.io.IOException;
import java.util.List;

/**
 * 
 * @author asus
 */
public class AndroidDataFactory {

	public static final String VIEC_LAM = "ViecLam";
	public static final String KHOA_HOC = "KhoaHoc";
	public static final String TIN_MOI = "TinMoi";

	/**
	 * 
	 * @param strData
	 *            such as: ViecLam, KhoaHoc
	 * @return
	 */
	public static List<NewsPreview> getListNewsPreview(String strData)
			throws IOException {
		synchronized (strData) {

			String dataUrl = "";
			if (strData.equals(TIN_MOI)) {
				return AndroidGetData
						.getListNewNewsPreview(ConstantCompare.URL_TIN_MOI);
			} else if (strData.equals(VIEC_LAM)) {
				dataUrl = ConstantCompare.URL_VIEC_LAM;
			} else if (strData.equals(KHOA_HOC)) {
				dataUrl = ConstantCompare.URL_KHOA_HOC;
			}
			// if dataUrl is null, return null value
			// else return list of news
			if (dataUrl.equals("")) {
				return null;
			} else {
				return AndroidGetData.getListNewsPreview(dataUrl, true);
			}
		}
	}

	/**
	 * 
	 * @param strData
	 * @param pageIndex
	 * @return
	 * @throws IOException
	 */
	public static List<NewsPreview> getListNewsPreview(String strData,
			int pageIndex) throws IOException {
		String dataUrl = "";
		if (strData.equals(VIEC_LAM)) {
			dataUrl = ConstantCompare.URL_VIEC_LAM
					+ ConstantCompare.URL_PAGE_SUB + pageIndex;
		} else if (strData.equals(KHOA_HOC)) {
			dataUrl = ConstantCompare.URL_KHOA_HOC
					+ ConstantCompare.URL_PAGE_SUB + pageIndex;
		}

		// if dataUrl is null, return null value
		// else return list of news
		if (dataUrl.equals("")) {
			return null;
		} else {
			return AndroidGetData.getListNewsPreview(dataUrl, false);
		}
	}
}
